import { ref } from 'vue';

export function useFilterSearch(customTableRef: any) {
  // 缓存 slide / filter 的参数
  const filterSearchObj = ref({
    slide: {},
    filter: {}
  });

  // 快捷搜索（顶部筛选）
  const filterChange = (form: any) => {
    filterSearchObj.value.slide = form;
    search();
  };

  // 查询（表单提交）
  const onSubmit = (form: any) => {
    filterSearchObj.value.filter = form;
    search();
  };

  // 合并参数 + 调用表格的 search
  const search = () => {
    const { slide, filter } = filterSearchObj.value;
    customTableRef.value?.search({
      ...slide,
      ...filter
    });
  };

  return {
    filterSearchObj,
    filterChange,
    onSubmit,
    search
  };
}
